<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%
    response.setHeader("cache-control","public");
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE html>
<html>
<!-- 以往的组织考试记录,创建考试入口 -->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <title>在线考试系统</title>
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/css/font/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/css/examMng/core.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/css/style.default.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/static/css/bootstrap-table.css">
    <!--bootstrap基础引用 start-->
	<script type="text/javascript" src="<%=path%>/static/jstreeview/bootstrap/jquery-3.1.1.min.js"></script>
	<script type="text/javascript" src="<%=path%>/static/js/bootstrap.min.js"></script>
	<!--bootstrap基础引用 end-->
	<!--bootstrap-dialog start-->
	<link rel="stylesheet" type="text/css" href="<%=path%>/static/jstreeview/plugins/bootstrap-dialog/bootstrap-dialog.min.css">
	<script type="text/javascript" src="<%=path%>/static/jstreeview/plugins/bootstrap-dialog/bootstrap-dialog.min.js"></script>
	<!--bootstrap-dialog end-->
    <style type="text/css">
        .top-brgclr {
            height: 70px;
            padding: 15px;
            padding-left: 40px;
            padding-right: 40px;
            background-color: #4479AE;
            line-height: 40px;
            border-radius: 4px 4px 0 0;
        }

        .top-brgclr p {
            font-size: 16px !important;
            color: #FFFFFF;
            padding: 0;
            line-height: 40px;
        }

        .color-fff {
            color: #FFFFFF;

            font-weight: 600;
        }

        .add-exam {
            float: right;
            background-color: #5CB85C;
            border-radius: 4px;
            padding: 0;
            text-align: center;
            cursor: pointer;
            width: 120px;
            height: 40px;
            color: #FFFFFF;
        }
        .no-pad {
            padding: 0px
        }

    </style>
    <script src="<%=path%>/static/js/jquery-1.9.1.min.js"></script>
    <script src="<%=path%>/static/js/respond.js"></script>
</head>

<body>
<jsp:include page="../head.jsp" flush="true"/>
<div class="main-container">
    <div class="container body-box no-pad">
        <div class="col-lg-12 col-md-12  top-brgclr " id="ti" style="background: #4c4ca6;">
            <p class="col-lg-10 col-md-10 color-fff">已组织考试列表：</p>
            <div id="" class="add-exam col-lg-2 col-md-2 col-sm-2 hover1 hover2" style="background: #4c4ca6;border:solid 1px #ffffff;">
                <span class="glyphicon glyphicon-plus-sign margintop4"></span><span>&nbsp;新增考试</span>
            </div>
        </div>
        <div class="panel-body minheight">
            <div class="content">
                <div class="table-responsive">
                    <div id="toolbar">
                        <button class="btn btn-default" onclick="printPage()" data-toggle="modal">
                            <i class="glyphicon glyphicon-print"></i>
                            打印准考证
                        </button>
                    </div>
                    <table id="taskList_table" class="table-striped table-hover"
                           data-mobile-responsive="true"></table>
                </div>
            </div>
            <table id="table"></table>
        </div>
    </div>
</div>
<!--body end-->

<script type="text/javascript" src="<%=path%>/static/js/practice/exam-org.js"></script>
<script type="text/javascript" src="<%=path%>/static/js/examMng/common.js"></script>
<script type="text/javascript" src="<%=path%>/static/js/bootstrap-table.js"></script>
<script type="text/javascript" src="<%=path%>/static/js/bootstrap-table-zh-CN.js"></script>
<script type="text/javascript">
    $(function () {
        //考试管理主页面
        if (${role eq 'master'}) {
            $('#topMain').children().eq(0).addClass('active'); // 追加样式;
            $('#topMain').children().eq(0).children().attr('href', '#');
        } else if (${role eq 'trainee'}) {
            $('#topMain').children().eq(0).addClass('active'); // 追加样式;
            $('#topMain').children().eq(0).children().attr('href', '#');
        } else {
            $('#topMain').children().eq(5).addClass('active'); // 追加样式;
            $('#topMain').children().eq(5).children().attr('href', '#');
        }
    });

    function AddFunctionAlty(value, row, index) {

        if (row.publish == '未发布') {
            return [
                '<button id="edit",type="button" class="btn btn-default">编辑</button>&nbsp;' +
                '<button id="del",type="button" class="btn btn-default">删除</button>'
            ].join("");
        } else {
            if(row.examStatus == 1) {
                return [
                    '<button id="view",type="button" class="btn btn-default">预览</button> &nbsp;' +
                    '<button id="copy",type="button" class="btn btn-default">复制</button>&nbsp;' +
                    '<button id="opened",type="button" class="btn btn-default" disabled="true">已启用</button>&nbsp;'
                ].join("");
            } else {
                return [
                    '<button id="view",type="button" class="btn btn-default">预览</button> &nbsp;' +
                    '<button id="copy",type="button" class="btn btn-default">复制</button>&nbsp;' +
                    '<button id="open",type="button" class="btn btn-default">启用</button>&nbsp;'
                ].join("");
            }

        }
    }
function printPage(){
    //使用getSelections即可获得，row是json格式的数据
    var rows = $("#table").bootstrapTable('getSelections');
    if (rows.length!=1){
        BootstrapDialog.show({
            type : BootstrapDialog.TYPE_DEFAULT,
            title : '提示 ',
            message : '请选择一场考试',
            size : BootstrapDialog.SIZE_SMALL,//size为小，默认的对话框比较宽
            buttons : [ {// 设置关闭按钮
                label : '确定',
                action : function(e) {
                    e.close();
                }
            } ]
        });
    }
    var examId = rows[0].examId;
    var myForm = document.createElement("form");
    myForm.method = "post";
    myForm.action = "<%=basePath%>exam/printPage";
    var myInput = document.createElement("input");
    myInput.setAttribute("name", "examId");  // 为input对象设置name
    myInput.setAttribute("value",examId);  // 为input对象设置value
    myForm.appendChild(myInput);
    document.body.appendChild(myForm);
    myForm.submit();
    document.body.removeChild(myForm);  // 提交后移除创建的form
}
    window.operateEvents = {
        'click #view': function (e, value, row, index) {
            var myForm = document.createElement("form");
            myForm.method = "post";
            myForm.action = "<%=basePath %>exam/toExamDetail";
            var myInput = document.createElement("input");
            myInput.setAttribute("name", "examId");  // 为input对象设置name
            myInput.setAttribute("value", row.examId);  // 为input对象设置value
            myForm.appendChild(myInput);
            document.body.appendChild(myForm);
            myForm.submit();
            document.body.removeChild(myForm);  // 提交后移除创建的form
        },
        'click #edit': function (e, value, row, index) {
            var myForm = document.createElement("form");
            myForm.method = "post";
            myForm.action = "<%=basePath %>exam/editExam";
            var myInput = document.createElement("input");
            myInput.setAttribute("name", "examId");  // 为input对象设置name
            myInput.setAttribute("value", row.examId);  // 为input对象设置value
            myForm.appendChild(myInput);
            document.body.appendChild(myForm);
            myForm.submit();
            document.body.removeChild(myForm);  // 提交后移除创建的form

        },
        'click #open': function (e, value, row, index) {
            $.ajax({
                type: "POST",
                url: "<%=basePath %>exam/openExam",
                data: {"examId": row.examId},
                success: function (data) {
                    $('#table').bootstrapTable('refresh', {
                        method : 'get',
                        dataType : 'json',
                        contentType : "application/x-www-form-urlencoded",
                        url: "<%=path%>/exam/examList",
                        cache : false,
                    });
                    if (data.status == 1) {
                    	BootstrapDialog.confirm({
            				title : '提示',
            				message : data.msg,
            				size : BootstrapDialog.SIZE_SMALL,
            				type : BootstrapDialog.TYPE_DEFAULT,
            				closable : true,
            				btnCancelLabel : '取消',
            				btnOKLabel : '确定'
            			});
                    }
                }
            })
        }, 'click #del': function (e, value, row, index) {
            $.ajax({
                type: "post",
                url: '<%=basePath %>exam/delExam',
                data: {"examId": row.examId},
                success: function (data) {
                    if (data.status == 1) {
                    	BootstrapDialog.confirm({
            				title : '提示',
            				message : data.msg,
            				size : BootstrapDialog.SIZE_SMALL,
            				type : BootstrapDialog.TYPE_DEFAULT,
            				closable : true,
            				btnCancelLabel : '取消',
            				btnOKLabel : '确定',
            				callback:function(result){
                                window.location.reload();
            				}
            			});
                    }
                }
            })
        }, 'click #copy': function (e, value, row, index) {
            $.ajax({
                type: "post",
                url: '<%=basePath %>exam/copyExam',
                data: {"examId": row.examId},
                success: function (data) {
                	BootstrapDialog.confirm({
        				title : '提示',
        				message : data[0].msg,
        				size : BootstrapDialog.SIZE_SMALL,
        				type : BootstrapDialog.TYPE_DEFAULT,
        				closable : true,
        				btnCancelLabel : '取消',
        				btnOKLabel : '确定',
        				callback:function(result){
                            window.location.reload();
        				}
        			});
                }
            })
        }
    };
    //类名为minheight的div下的所有table元素点击跳转事件（跳转到‘exam-org-deta.htm’）
    $(document).ready(function () {

        $(".minheight").children("table").click(function () {
            self.location = 'exam-detail.html';
        })
        //新增考试链接
        $(".add-exam").click(function () {
            self.location = '<%=basePath%>exam/toAddExam';
        });
        //鼠标滑过事件
        $(".hover1").mouseover(function () {
            $(this).css("background-color", "#4c4ca6")
        });
        $(".hover2").mouseleave(function () {
            $(this).css("background-color", "#4c4ca6")
        })
    });
    $('#table').bootstrapTable({
        "pagination": true,
        "search": true,
        method: 'post',
        dataType: 'json',
        contentType: "application/x-www-form-urlencoded",
        url: '<%=basePath %>exam/examList',
        striped: false,
        toolbar: "#toolbar",
        showHeader: true,
        pageNumber: 1,
        showRefresh: true,                  //是否显示刷新按钮
        pagination : true,//是否分页
		sidePagination : 'client',//server:服务器端分页|client：前端分页
		pageSize : 4,//单页记录数
		pageList : [ 5, 10, 20, 30 ],//可选择单页记录数
        clickToSelect: true,                //是否启用点击选中行
        columns: [{
            checkbox: true
        },{
            field: 'number',
            title: '序号',
            align: "center",
            valign: "middle",
            formatter: function (value, row, index) {
                return index + 1;
            }
        }, {
            field: 'examName',
            title: '考试名称',
            align: "center",
            valign: "middle"
        }, {
            field: 'studentCount',
            title: '考生人数',
            align: "center",
            valign: "middle"
        }, {
            field: 'publish',
            title: '考试状态',
            align: "center",
            valign: "middle"
        }, {
            field: 'Operations',
            title: '操作',
            events: 'operateEvents',
            formatter: 'AddFunctionAlty',
            align: "center",
            valign: "middle"
        }],
        onClickRow: function (row, $element, field) {
            if ( field !==0 && field !== "Operations" ) {
                var myForm = document.createElement("form");
                myForm.method = "post";
                myForm.action = "<%=basePath %>examCenter/queryResultsPage";
                var myInput = document.createElement("input");
                myInput.setAttribute("name", "examid");  // 为input对象设置name
                myInput.setAttribute("value", row.examId);  // 为input对象设置value
                myForm.appendChild(myInput);
                document.body.appendChild(myForm);
                myForm.submit();
                document.body.removeChild(myForm);  // 提交后移除创建的form
            }
        },
        onLoadSuccess:function(){
            $(".bs-checkbox").css({'text-align':'center','vertical-align':'middle'});
        }

    });



</script>
</body>
</html>
